package com.future.mayi.activity;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.future.baselib.entity.DefaultResponse;
import com.future.baselib.utils.ApiCst;
import com.future.baselib.utils.CommonUtils;
import com.future.baselib.utils.HttpRequest;
import com.future.mayi.R;
import com.future.mayi.app.App;
import com.future.mayi.dialog.CommonDialog;
import com.future.mayi.dialog.RecycleSelectGoodsDialog;
import com.future.mayi.dialog.SoldChangeDialog;
import com.future.mayi.model.AddressModel;
import com.future.mayi.model.ConsignOrderGoodsModel;
import com.future.mayi.model.RecycleOrderModel;
import com.future.mayi.model.SellerAddressModel;
import com.future.mayi.model.interfaces.SoldChangeListener;
import com.future.mayi.response.RecycleOrderInfoResponse;
import com.future.mayi.response.SellerAddressResponse;
import com.future.mayi.utils.HCUtils;
import com.future.mayi.utils.KefuUtils;
import com.future.mayi.utils.Navigator;
import com.future.mayi.utils.PriceUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

public class RecycleOrderActivity extends BaseTitleActivity implements SoldChangeListener {
    @BindView(R.id.ll_jimai_agreement)
    View llJimaiAgreement;
    @BindView(R.id.tv_jimai_agreement_title)
    TextView tvJimaiAgreementTitle;
    @BindView(R.id.tv_jimai_agreement_enter)
    TextView tvJimaiAgreementRnter;


    @BindView(R.id.tv_express_company)
    TextView tvExpressCompany;
    @BindView(R.id.tv_express_find)
    TextView tvExpressFind;
    @BindView(R.id.tv_express_code)
    TextView tvExpressCode;
    @BindView(R.id.ll_express)
    LinearLayout llExpress;
    @BindView(R.id.tv_sub_title)
    TextView tvSubTitle;
    @BindView(R.id.ll_goods)
    LinearLayout llGoods;
    @BindView(R.id.tv_jijian_name)
    TextView tvJijianName;
    @BindView(R.id.tv_jijian_phone)
    TextView tvJijianPhone;
    @BindView(R.id.tv_jijian_address)
    TextView tvJijianAddress;
    @BindView(R.id.ll_jijian_address)
    LinearLayout llJijianAddress;
    @BindView(R.id.ll_server)
    LinearLayout llServer;
    @BindView(R.id.tv_order_code)
    TextView tvOrderCode;
    @BindView(R.id.ll_order_code_copy)
    LinearLayout llOrderCodeCopy;
    @BindView(R.id.tv_order_time)
    TextView tvOrderTime;
    @BindView(R.id.tv_order_state)
    TextView tvOrderState;
    @BindView(R.id.tv_enter)
    TextView tvEnter;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_phone)
    TextView tvPhone;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.ll_huiji_show_address)
    LinearLayout llHuijiShowAddress;
    @BindView(R.id.tv_add_address)
    TextView tvAddAddress;
    @BindView(R.id.ll_agreement)
    View llAgreement;
    @BindView(R.id.tv_agreement)
    TextView tvAgreement;
    @BindView(R.id.tv_agreements)
    TextView tvAgreements;
    @BindView(R.id.ll_huiji_address)
    LinearLayout llHuijiAddress;
    @BindView(R.id.iv_huiji_right)
    View ivHuijiRight;

    private RecycleOrderModel model;
    private SellerAddressModel jijianModel;
    private String orderId;

    //1是寄卖 2是回收
    private int style = 0;
    private LayoutInflater mInflater;

    //style 1是寄卖 2是回收
    public static void startActivity(Context context, String orderId, int style) {
        context.startActivity(new Intent(context, RecycleOrderActivity.class).putExtra("orderId", orderId).putExtra("style", style));
    }

    public static void startActivity(Context context, RecycleOrderModel model, int style) {
        context.startActivity(new Intent(context, RecycleOrderActivity.class).putExtra("model", model).putExtra("style", style));
    }


    @Override
    protected void initTopBar() {
        initBack();
        getTitleText().setText("待报价");
    }

    @Override
    protected void initLayout() {
        setContentView(R.layout.activity_sold_order);
    }

    @Override
    protected void initView() {
        mInflater = LayoutInflater.from(this);
    }

    @Override
    protected void initDates() {
        orderId = getIntent().getStringExtra("orderId");
        style = getIntent().getIntExtra("style", 1);
        tvSubTitle.setText(style == 1 ? "寄卖商品" : "回收商品");


//        if (style == 2) {
//            llAgreement.setVisibility(View.VISIBLE);
//            tvAgreement.setText(style == 1 ? "寄卖协议：" : "回收协议：");
//            tvAgreements.setText(style == 1 ? "点击查看寄卖协议" : "点击查看回收协议");
//        }

        if (getIntent().getSerializableExtra("model") != null)
            model = (RecycleOrderModel) getIntent().getSerializableExtra("model");
        if (model != null) {
            orderId = String.valueOf(model.getOrder_id());
        }
        setView();


    }

    @Override
    protected void initListener() {
        getRightText().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (model == null) return;
                if (model.getStatus() == 0 || model.getStatus() == 10) {
                    //取消订单
                    new CommonDialog.Builder(mContext)
                            .setCancelable(false)
                            .setMessage("确定取消该订单吗？")
                            .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                }
                            })
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.dismiss();
                                    confirmOrCancel();
                                }
                            }).show();
                }
            }
        });

    }


    @OnClick({R.id.tv_jimai_agreement_enter, R.id.tv_express_find, R.id.tv_enter, R.id.tv_add_address, R.id.ll_huiji_show_address, R.id.ll_order_code_copy, R.id.ll_server, R.id.ll_agreement})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_jimai_agreement_enter:
                JimaiAgreementActivity.startActivity(this, orderId);
                break;
            case R.id.tv_express_find:
                //查寄件物流
                CourierInfoActivity.startActivity(this, String.valueOf(RecycleOrderActivity.this.model.getOrder_id()), "", 0);
                break;
            case R.id.tv_enter:
                tvEnter.setEnabled(false);
                enter();
                tvEnter.setEnabled(true);
                break;
            case R.id.tv_add_address:
            case R.id.ll_huiji_show_address:
                if (view.getId() == R.id.ll_huiji_show_address && ivHuijiRight.getVisibility() != View.VISIBLE)
                    return;
                Intent intent = new Intent(this, AddressActivity.class);
                intent.putExtra("isSelect", true);
                startActivityForResult(intent, 221);
                break;
            case R.id.ll_order_code_copy:
                findViewById(R.id.ll_order_code_copy).setEnabled(false);
                CommonUtils.clipData(this, model.getOrder_no());
                toast("复制成功");
                findViewById(R.id.ll_order_code_copy).setEnabled(true);
                break;
            case R.id.ll_server:
                KefuUtils.startActivity(this);
                break;
            case R.id.ll_agreement:
                Navigator.navigatorProtocolActivity(RecycleOrderActivity.this, style == 2);
                break;


        }
    }


    private RecycleSelectGoodsDialog selectGoodsDialog;

    private void enter() {
        if (model.getStatus() == 10) {
            if (style == 2)
                EdtExpressActivity.startActivity(this, orderId, true);
            else {
                if (selectGoodsDialog == null)
                    selectGoodsDialog = new RecycleSelectGoodsDialog(this);

                if (model.getGoods_item() == null) return;
                if (model.getGoods_item().size() == 0) return;
                List<ConsignOrderGoodsModel> models = new ArrayList<>(model.getGoods_item().size());
                for (ConsignOrderGoodsModel goodsModel : model.getGoods_item()) {
                    if (goodsModel == null) continue;
                    if (goodsModel.getGoods_status() != 50)
                        models.add(goodsModel);
                }
                selectGoodsDialog.show(orderId, models);
            }
        }
    }


    private void setView() {
        if (model == null) return;
        TextView tvTitle = getTitleText();
        TextView tvRight = getRightText();
        tvRight.setVisibility(View.GONE);
        llExpress.setVisibility(View.GONE);
        tvEnter.setVisibility(View.GONE);
//        订单状态 0-待报价 10-已报价 20-已寄件 30-出售中(寄卖专用) 40-已完成 90-已取消

        switch (model.getStatus()) {
            // 0-待报价
            case 0:
                ivHuijiRight.setVisibility(View.VISIBLE);
                setText(tvTitle, "待报价");
                setText(tvOrderState, "待报价");
                tvRight.setVisibility(View.VISIBLE);
                setText(tvRight, "取消订单");
                llJimaiAgreement.setVisibility(View.GONE);
                break;
            // 10-已报价
            case 10:
                ivHuijiRight.setVisibility(View.VISIBLE);
                tvEnter.setVisibility(View.VISIBLE);
                setText(tvEnter, "填写寄件物流");
                setText(tvTitle, "已报价");
                setText(tvOrderState, "已报价");
                tvRight.setVisibility(View.VISIBLE);
                setText(tvRight, "取消订单");
                llJimaiAgreement.setVisibility(View.GONE);
                break;
            //20-已寄件
            case 20:
                ivHuijiRight.setVisibility(View.GONE);
                setLlExpress();
                setText(tvTitle, "已寄件");
                setText(tvOrderState, "已寄件");
                llJimaiAgreement.setVisibility(View.VISIBLE);
                break;
            // 30-出售中
            case 30:
                ivHuijiRight.setVisibility(View.GONE);
                setText(tvTitle, "寄卖中");
                setText(tvOrderState, "寄卖中");
                llJimaiAgreement.setVisibility(View.VISIBLE);
                break;
            // 40-已完成
            case 40:
                ivHuijiRight.setVisibility(View.GONE);
                setText(tvTitle, "已完成");
                setText(tvOrderState, "已完成");
                llJimaiAgreement.setVisibility(View.VISIBLE);
                break;
            // 90-已取消
            case 90:
                ivHuijiRight.setVisibility(View.GONE);
                setText(tvTitle, "已取消");
                setText(tvOrderState, "已取消");
                llJimaiAgreement.setVisibility(View.GONE);
                break;
            default:
                llJimaiAgreement.setVisibility(View.GONE);
                break;
        }

        if (llJimaiAgreement.getVisibility() == View.VISIBLE) {
            if (model.getProtocol_status() == 0) {
                tvJimaiAgreementTitle.setText("《寄卖协议单》生成中...");
                tvJimaiAgreementRnter.setText("");
                tvJimaiAgreementRnter.setVisibility(View.GONE);
            } else if (model.getProtocol_status() == 1) {
                tvJimaiAgreementTitle.setText("请及时确认《寄卖协议单》");
                tvJimaiAgreementRnter.setText("去确认>");
                tvJimaiAgreementRnter.setVisibility(View.VISIBLE);
            } else if (model.getProtocol_status() == 10) {
                tvJimaiAgreementTitle.setText("《寄卖协议单》已确认");
                tvJimaiAgreementRnter.setText("查看>");
                tvJimaiAgreementRnter.setVisibility(View.VISIBLE);
            }
        }


        if (style == 1) {
            if (model.getStatus() == 0) {
                llHuijiAddress.setVisibility(View.GONE);
            } else {
                if (model.getStatus() == 90 && TextUtils.isEmpty(model.getAddress())) {
                    llHuijiAddress.setVisibility(View.GONE);
                } else {
                    llHuijiAddress.setVisibility(View.VISIBLE);
                    if (TextUtils.isEmpty(model.getAddress())) {
                        llHuijiShowAddress.setVisibility(View.GONE);
                        tvAddAddress.setVisibility(View.VISIBLE);
                    } else {
                        llHuijiShowAddress.setVisibility(View.VISIBLE);
                        tvAddAddress.setVisibility(View.GONE);
                        setText(tvName, model.getAddress_user());
                        setText(tvPhone, model.getAddress_tel());
                        setText(tvAddress, model.getAddress());
                    }
                }
            }
        } else {
            llHuijiAddress.setVisibility(View.GONE);
        }


        llGoods.removeAllViews();
        if (model.getGoods_item() != null && model.getGoods_item().size() > 0) {
            for (ConsignOrderGoodsModel model : model.getGoods_item()) {
                View view = mInflater.inflate(R.layout.layout_recycle_goods_item, llGoods, false);
                ImageView ivImg = (ImageView) view.findViewById(R.id.iv_img);
                TextView tvGoodsTitle = (TextView) view.findViewById(R.id.tv_title);
                TextView tvTag = view.findViewById(R.id.tv_tag);
                View llEnter = view.findViewById(R.id.ll_enter);
                TextView tvEnter = view.findViewById(R.id.tv_enter);
                TextView tvWuliu = (TextView) view.findViewById(R.id.tv_wuliu);
                View llQw = view.findViewById(R.id.ll_qw);
                TextView tvQwType = (TextView) view.findViewById(R.id.tv_qw_type);
                TextView tvQwPrice = (TextView) view.findViewById(R.id.tv_qw_price);
                View llPt = view.findViewById(R.id.ll_pt);
                TextView tvPtType = (TextView) view.findViewById(R.id.tv_pt_type);
                TextView tvPtPrice = (TextView) view.findViewById(R.id.tv_pt_price);
                View rlOther = view.findViewById(R.id.rl_other);


                switch (this.model.getStatus()) {
                    // 0-待报价
                    case 0:
                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("期望价格：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));
                        break;
                    // 10-已报价
                    case 10:
                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("期望价格：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));
                        if (model.getPlatform_max_price() > 0) {
                            llPt.setVisibility(View.VISIBLE);
                            tvPtType.setText("平台报价：¥");
                            tvPtPrice.setText(PriceUtils.getPriceText2(model.getPlatform_min_price()) + "~" + PriceUtils.getPriceText2(model.getPlatform_max_price()));
                        }
                        break;
                    //20-已寄件
                    case 20:
                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("期望价格：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));
                        if (model.getPlatform_max_price() > 0) {
                            llPt.setVisibility(View.VISIBLE);
                            tvPtType.setText("平台报价：¥");
                            tvPtPrice.setText(PriceUtils.getPriceText2(model.getPlatform_min_price()) + "~" + PriceUtils.getPriceText2(model.getPlatform_max_price()));
                        }
                        break;
                    // 30-出售中
                    case 30:
                        if (model.getGoods_status() != 0
                                && model.getGoods_status() != 50
                                && model.getGoods_status() != 90) {
                            llQw.setVisibility(View.VISIBLE);
                            tvQwType.setText("到手价：¥");
                            tvQwPrice.setText(PriceUtils.getPriceText2(model.getPrice()));
                        }
                        break;
                    // 40-已完成
                    case 40:
                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("到手价：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getPrice()));
                        break;
                    // 90-已取消
                    case 90:
                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("期望价格：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));
                        break;
                    default:
                        break;
                }


                if (style == 1) {
                    //状态 0-待上架 1-寄卖中 2-出售中 10-已寄回 20-已售出 30-已结款 40-已回收 50-平台拒收
                    if (this.model.getStatus() == 30)
                        switch (model.getGoods_status()) {
                            case 0: {
                                tvTag.setVisibility(View.GONE);
                            }
                            break;
                            case 1: {
                                tvTag.setText("寄卖中");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_red);
                                tvTag.setTextColor(getResources().getColor(R.color.red));
                            }
                            break;
                            case 2: {
                                tvTag.setText("出售中");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_red);
                                tvTag.setTextColor(getResources().getColor(R.color.red));
                                llEnter.setVisibility(View.VISIBLE);
                                tvEnter.setText("急用钱");
                            }
                            break;
                            case 10: {
                                tvTag.setText("已寄回");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_hui);
                                tvWuliu.setVisibility(View.VISIBLE);
                            }
                            break;
                            case 20: {
                                tvTag.setText("已卖出");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_hui);
                                llEnter.setVisibility(View.VISIBLE);
                                tvEnter.setText("去结款");
                            }
                            break;
                            case 30: {
                                tvTag.setText("已结款");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_hui);
                            }
                            break;
                            case 40: {
                                tvTag.setText("已回收");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_hui);
                            }
                            break;
                            case 50: {
                                llQw.setVisibility(View.VISIBLE);
                                tvQwType.setText("期望价格：¥");
                                tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));

                                llPt.setVisibility(View.VISIBLE);
                                tvPtType.setText("平台拒收该商品");
                                tvPtType.setTextColor(getResources().getColor(R.color.red));
                                tvPtPrice.setText("");

                                tvTag.setVisibility(View.GONE);
                            }
                            break;
                            //已取消
                            case 90:
                                tvTag.setText("已取消");
                                tvTag.setBackgroundResource(R.drawable.bg_recycler_hui);
                                break;
                        }


                    if (model.getGoods_status() == 50 && (this.model.getStatus() == 10 || this.model.getStatus() == 20 || this.model.getStatus() == 30 || this.model.getStatus() == 40)) {
                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("期望价格：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));

                        llPt.setVisibility(View.VISIBLE);
                        tvPtType.setText("平台拒收该商品");
                        tvPtType.setTextColor(getResources().getColor(R.color.red));
                        tvPtPrice.setText("");

                        tvTag.setVisibility(View.GONE);
                    }


                } else {
                    //回收
                    llQw.setVisibility(View.VISIBLE);
                    tvQwType.setText("期望价格：¥");
                    tvQwPrice.setText(PriceUtils.getPriceText2(model.getExpect_price()));


                    llPt.setVisibility(View.GONE);

                    if (model.getPrice() > 0) {
                        llPt.setVisibility(View.VISIBLE);
                        tvPtType.setText("实际价格：¥");
                        tvPtPrice.setText(PriceUtils.getPriceText2(model.getPrice()));
                        tvPtType.setTextColor(getResources().getColor(R.color.red));
                        tvPtPrice.setTextColor(getResources().getColor(R.color.red));


                        llQw.setVisibility(View.VISIBLE);
                        tvQwType.setText("平台报价：¥");
                        tvQwPrice.setText(PriceUtils.getPriceText2(model.getPlatform_min_price()) + "~" + PriceUtils.getPriceText2(model.getPlatform_max_price()));


                    } else if (model.getPlatform_max_price() > 0) {
                        llPt.setVisibility(View.VISIBLE);
                        tvPtType.setText("平台报价：¥");
                        tvPtPrice.setText(PriceUtils.getPriceText2(model.getPlatform_min_price()) + "~" + PriceUtils.getPriceText2(model.getPlatform_max_price()));

                        tvPtType.setTextColor(getResources().getColor(R.color.text_color855424));
                        tvPtPrice.setTextColor(getResources().getColor(R.color.text_color855424));
                    }
                    llEnter.setVisibility(View.GONE);

                }

                llEnter.setTag(model);
                llEnter.setOnClickListener(this);
                tvWuliu.setTag(model);
                tvWuliu.setOnClickListener(this);
                setText(tvGoodsTitle, model.getGoods_name());
                HCUtils.loadWebImg(this, ivImg, model.getImg_list() == null || model.getImg_list().size() == 0 ? "" : model.getImg_list().get(0));
                view.setTag(model);
                llGoods.addView(view);

                if (llQw.getVisibility() == View.VISIBLE || llPt.getVisibility() == View.VISIBLE || llEnter.getVisibility() == View.VISIBLE || tvWuliu.getVisibility() == View.VISIBLE) {
                    rlOther.setVisibility(View.VISIBLE);
                }
            }
        }
        setText(tvOrderCode, "订单编号：".concat(model.getOrder_no() == null ? "" : model.getOrder_no()));
        setText(tvOrderTime, model.getCreatetime());
    }

    private void getDefaultAddress() {

    }


    private void setJijian() {
        if (jijianModel == null) {
            llJijianAddress.setVisibility(View.GONE);
            return;
        }
        llJijianAddress.setVisibility(View.VISIBLE);
        tvJijianName.setText(jijianModel.getUser());
        tvJijianPhone.setText(jijianModel.getTel());
        tvJijianAddress.setText(jijianModel.getAddress());
    }

    /**
     * 设置物流
     */
    public void setLlExpress() {
        llExpress.setVisibility(View.VISIBLE);
        setText(tvExpressCompany, "物流公司：" + model.getJj_express_name());
        setText(tvExpressCode, "物流单号：" + model.getJj_express_no());
    }


    private void getData() {
        new HttpRequest<RecycleOrderInfoResponse>()
                .with(this).setApiCode(ApiCst.Consignorderdetail)
                .addParam("token", App.getToken(mContext))
                .addParam("order_id", orderId)
                .setListener(new HttpRequest.OnNetworkListener<RecycleOrderInfoResponse>() {
                    @Override
                    public void onSuccess(RecycleOrderInfoResponse response) {
                        model = response.model;
                        getJijian();
                        setView();
                        if (tvAddAddress.getVisibility() == View.VISIBLE)
                            getDefaultAddress();
                    }

                    @Override
                    public void onFail(String message, RecycleOrderInfoResponse response) {
                        toast(message);
                        finish();
                    }
                }).start(new RecycleOrderInfoResponse());


    }

    private void getJijian() {
        if (model.getStatus() == 0) {
            jijianModel = null;
            setJijian();
        } else
            new HttpRequest<SellerAddressResponse>()
                    .with(this)
                    .setApiCode(ApiCst.getSellerAddress)
                    .addParam("key", style == 1 ? "jm" : "hs")//关键字 jd-鉴定 yh-养护 jm-寄卖 hs-回收 默认不传为jd
                    .setListener(new HttpRequest.OnNetworkListener<SellerAddressResponse>() {
                        @Override
                        public void onSuccess(SellerAddressResponse response) {
                            jijianModel = response.getAddressModel();
                            setJijian();
                        }

                        @Override
                        public void onFail(String message, SellerAddressResponse response) {
                            toast(message);
                        }
                    })
                    .start(new SellerAddressResponse());
    }

    @Override
    protected void onResume() {
        super.onResume();
        getData();
    }

    private SoldChangeDialog soldChangeDialog;

    @Override
    public void onClick(View v) {
        super.onClick(v);
        if (v.getTag() != null && v.getTag() instanceof ConsignOrderGoodsModel) {
            ConsignOrderGoodsModel model = (ConsignOrderGoodsModel) v.getTag();
            //状态 0-待上架 1-寄卖中 2-出售中 10-已寄回 20-已售出 30-已结款 40-已回收 50-平台拒收
            if (model.getGoods_status() == 2) {
                //急用钱
                if (soldChangeDialog == null)
                    soldChangeDialog = new SoldChangeDialog(this);
                soldChangeDialog.show(this, model);
            } else if (model.getGoods_status() == 10) {
                //查寄回物流
                CourierInfoActivity.startActivity(this, String.valueOf(RecycleOrderActivity.this.model.getOrder_id()), String.valueOf(model.getOrder_goods_id()), 1);
            } else if (model.getGoods_status() == 20) {
                JimaiPayActivity.startActivity(this, String.valueOf(model.getOrder_goods_id()));
            }
        }
    }


    /**
     * 确认收货或取消订单
     * 取消订单
     */
    public void confirmOrCancel() {
        new HttpRequest<DefaultResponse>()
                .with(this).setApiCode(ApiCst.cancelOrderConsignorder)
                .addParam("token", App.getToken(mContext))
                .addParam("order_id", orderId)
                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
                    @Override
                    public void onSuccess(DefaultResponse response) {
                        toast(response.message);
                        getData();
                    }

                    @Override
                    public void onFail(String message, DefaultResponse response) {
                        toast(message);
                    }
                }).start(new DefaultResponse());

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == Activity.RESULT_OK && requestCode == 221 && data != null) {
            AddressModel addressModel = (AddressModel) data.getSerializableExtra("model");
            setHuiji(addressModel);
        }
    }


    private void setHuiji(AddressModel addressModel) {
        if (addressModel == null) return;
        new HttpRequest<DefaultResponse>()
                .with(this).setApiCode(ApiCst.addAddressConsignorder)
                .addParam("token", App.getToken(mContext))
                .addParam("order_id", orderId)
                .addParam("address_id", addressModel.getAddress_id())
                .setListener(new HttpRequest.OnNetworkListener<DefaultResponse>() {
                    @Override
                    public void onSuccess(DefaultResponse response) {
                        getData();
                    }

                    @Override
                    public void onFail(String message, DefaultResponse response) {
                        toast(message);
                    }
                }).start(new DefaultResponse());
    }

    private void updateHuiji(AddressModel addressModel) {
        if (addressModel == null) return;
    }

    @Override
    public void onReduction(ConsignOrderGoodsModel tag) {
        if (tag == null) return;
        EdtPriceActivity.starActivity(this, tag);
//        KefuUtils.startActivity(this);
    }

    @Override
    public void onRecycle(ConsignOrderGoodsModel tag) {
        KefuUtils.startActivity(this);
    }

    @Override
    public void onBack(ConsignOrderGoodsModel tag) {
        KefuUtils.startActivity(this);
    }
}
